package project2.ui.game.auto;

import project2.config.Config;
import project2.entity.weapon.Bomb;
import project2.entity.weapon.CatchableWeapon;
import project2.resources.Sounds;
import project2.type.BulletType;
import project2.ui.game.GamePlayingPanel;

public class CatchableWeaponMove {

    private final GamePlayingPanel panel;

    public CatchableWeaponMove(GamePlayingPanel panel) {
        this.panel = panel;
    }

    public void run(CatchableWeapon weapon) {
        if (weapon == null) {
            return;
        }
        weapon.setPosY(weapon.getPosY() + weapon.getSpeed());// 更改位置

        if (weapon.getPosY() >= panel.getHeight()) {// 超出面板范围，则清除
            weapon.setWeaponDisappear(true);
        } else if (weapon.getRectangle().intersects(panel.myPlane.getRectangle())) {// 可拾取武器与主角碰撞检测
            switch (weapon.getWeaponType()) {
                case BOMB:
                    if (panel.myPlane.getHoldBombCount() < Config.BOMB_MAX_HOLD_COUNT) {
                        panel.myPlane.getHoldBombList().add((Bomb) weapon);
                        Sounds.getBombSoundPlayer.play();
                    }
                    break;
                case DOUBLE_LASER:
                    panel.myPlane.setBulletType(BulletType.BLUE_BULLET);
                    Sounds.getDoubleLaserSoundPlayer.play();
                    break;
            }
            weapon.setWeaponDisappear(true);
        }
    }
}
